package configs

import (
	"fmt"
	"gopkg.in/yaml.v3"
	"io/ioutil"
	"log"
)

type conf struct {
	A string
	B struct {
		RenamedC int   `yaml:"c"`
		D        []int `yaml:",flow"`
	}
	Gin struct {
		Port string `yaml:"port"`
	}

	Log struct {
		Level    string `yaml:"level"`
		Name     string `yaml:"name"`
		Backups  int `yaml:"backups"`
		Age      int    `yaml:"age"`
		Size     int    `yaml:"size"`
		Compress bool   `yaml:"compress"`
	}
}

var Conf = conf{}

func LoadConf() {

	file, err := ioutil.ReadFile("./configs/conf.yaml")
	if err != nil {
		print(err)
	}
	err = yaml.Unmarshal(file, &Conf)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	d, err := yaml.Marshal(&Conf)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	fmt.Printf("=== load conf === :\n%s\n\n", string(d))
}
